set the visible of card field 1 to not the visible of card field 1
if the visible of card field 1 is true then
set the name of me to "Hide Pascal Source"
else set the name of me to "Show Pascal Source"
end mouseUp
-- part contents for background part 16
----- text -----
PRINTFIELD XCMD version 1.5.1
Kevin Calhoun
NOTE TO USERS OF EARLIER VERSIONS: The parameter list of PrintField changed with version 1.4. Please be sure to read "CHANGES FROM VERSIONS 1.0 AND 1.2" if you want to replace those earlier versions in your stacks.
The PrintField XCMD prints the text of a field in the field's current textFont, textSize, textStyle, textHeight, and width. You may supply additional information about margins in order to place the text anywhere you like on the page.
PrintField uses a dialog box to inform the user that printing is in progress. It passes to the printer driver the short name of the field to be printed as the document name.
In case of an error, PrintField returns an error message as the Result. Word 1 of this message will be "Error". If the user presses the cancel button in either of the print job dialog boxes, the Result will be "Cancel".
PrintField can print only one field at a time. It works with both the LaserWriter and the ImageWriter.
CHANGES FROM VERSIONS 1.0 AND 1.2
The parameter list changed with version 1.4 in order to accommodate users who wanted the option of skipping the Page Setup and Print Job dialog boxes. A new parameter, called dialogCount, was added after the field designation and before the margin settings to specify which of the print dialog boxes the user sees. If you used margin settings with earlier versions of PrintField, you will have to alter your scripts to accord with the new parameter list used by versions 1.4 and later.
Parameters given inside the brackets, such as <notNeeded>, are optional.
fieldDesignation:
You may designate the field to print in any way considered valid by HyperCard, by number, id, or name, with one exception: you can't use the field's name if it is more than one word. If you do use the field's name, don't put the field name in quotation marks, because nested quotations confuse HyperCard. (See the examples below.)
dialogCount:
If dialogCount is 2 (or anything other than 0 or 1), then the user will see both the Page Setup and the Print Job dialog boxes before the printing process begins. If dialogCount is 1, then the user will see only the Print Job dialog box. If dialogCount is 0, then neither of these dialog boxes will appear before printing. If you set dialogCount equal to 0 or 1, thereby suppressing one or both of the print dialogs, the default settings stored in the printer resource file will be used for the print job, just as if the user clicked "OK" without changing any of the settings in the dialog.
There is no way in this version to set such things as paper orientation or number of copies to values other than the defaults by any means other than the dialog boxes. Moreover, PrintField is unable to access the settings the user designates by choosing Page Setup from HyperCard's File menu. If you want to enable printing with settings other than the defaults, set dialogCount to 2.
Setting Margins:
Values for leftMargin, rightMargin, topMargin, and bottomMargin are given in pixels. According to QuickDraw, one pixel equals 1/72 inch; therefore you can specify a one inch margin by passing 72 as the margin parameter. If you don't supply margin parameters, PrintField defaults to half-inch margins on the top, left, and bottom of the page, and prints each line of the text about as wide as it appears on the screen.
Valid Examples--
1. PrintField "bkgnd field 1" -- default values will be used for margins
2. PrintField "bkgnd field 1",0,0,0,0,0 -- this will print as much as possible on a page
3. PrintField "card field id 22",2,72,72,72,72 -- by id, with one inch margins all around
4. PrintField "card field foo",2,72 -- by name, with a left margin one inch wide
See the script of the button "Print the Documentation" for another example.
It is possible to put the designation of the field into a variable and then pass the variable to PrintField, as follows…
on openField
if the optionKey is down then
put the name of the target into theName
put the id of the target into theField
if word 1 of theName is "card" then put "card field id " before theField
else put "field id " before theField
PrintField theField
end if
end openField
This handler prints a field if the field is clicked while the option key is down.
COPYING PRINTFIELD INTO YOUR STACKS
Warning to ResEdit and ResCopy users: PrintField requires a DLOG resource and a DITL resource as well as the XCMD resource--these resources are named "PrintField" and numbered 9140 (the same number as the PrintField XCMD) so you can find them easily. If either the DITL or the DLOG resource is not present, PrintField will still print properly, and printing can still be canceled by pressing command-period, but the user won't have the benefit of the information the dialog provides.
THE COMMAND-PERIOD PROBLEM
In early versions of HyperCard, when background printing was not enabled, the print job was not aborted properly when the user pressed command-period. HyperCard intercepted command-period keypresses before the Print Manager saw them and interpreted them as the user's signal to abort the execution of the current script. Therefore, the print job was aborted by HyperCard preventing PrintField from completing and exiting normally and not according to the proper method, which requires further communication with the Print Manager for the printer driver to clean up after itself. A number of difficulties would arise as a result--when the current printer was a LaserWriter, its status dialog box was not removed from the screen, and on occasion the Macintosh would bomb. This problem has gone away in HyperCard 1.2.2--command-period keypresses no longer interrupt XCMD's.
CHANGE HISTORY
3/7/88 1.0
3/17/88 1.1 -- Fixed erasure problem when printing on LaserWriter with a small lineHeight.
4/7/88 1.2 -- Dialog now centered on third party screens also.
6/8/88 1.4 -- Fixed problem printing multiple pages on ImageWriter. Improved error handling to accord with changes in HyperCard 1.2. Added option of skipping one or both print dialogs. Improved WYSIWYG default margins (the width of the line on the page is much more often the same as it appears on the screen). Fixed problem with last line of page when font ascent was small.
2/24/89 1.5 -- Altered source code for compatibility with MPW Pascal 3.0. Added use of watch cursor, because Roger waved the interface guidelines at me.
3/15/89 1.5.1 -- Switched to trap-based printing manager. PrintField now requires System 4.1 or later, which shouldn't be a hardship for HyperCard users. Also, now returns "Cancel" as the result when user presses cancel button in either dialog.
NOTES FOR PROGRAMMERS:
PrintField contains code for finding out about all the properties of a field. You might find the functions GetFontOfField, GetJustOfField, etc., to be useful in your XCMD's.
-- part contents for card part 12
----- text -----
UNIT PrintUnit;
{ PrintField XCMD ©1988-1989 by the Trustees of Dartmouth College }